<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head th:replace="~{common::header('需求计划确认')}"></head>
<body>
<div class="container-fluid">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <ul class="breadcrumb">
                <li>
                    <a>选择物资</a>
                </li>
                <li>
                    <a>录入需求计划</a>
                </li>
                <li class="active">
                    需求计划确认
                </li>
            </ul>
        </div>
    </div>

    <div class="row clearfix">
        <div class="col-md-12 column">
            <div class="col-sm-4 col-md-3 column form-inline">
                <label for="a1">产品编码:</label>
                <input type="text" class="form-control" id="a1" placeholder="产品编码">
            </div>
            <div class="col-sm-4 col-md-3 column form-inline">
                <label for="a2">产品名称:</label>
                <input type="text" class="form-control" id="a2" placeholder="产品名称">
            </div>
            <div class="col-sm-4 col-md-3 column form-inline">
                <label for="a3">状态:</label>
                <select class="form-control  " id="a3">
                    <option>全部</option>
                    <option value="C001-10">未确认</option>
                    <option value="C001-20">确认</option>
                </select>
            </div>
            <div class="col-sm-12 col-md-3 column" >
                <button type="button" class="btn btn-primary" onclick="btn2()" style="margin-right: 10px">搜索</button>
                <button type="button" class="btn btn-primary" onclick="btn3()" >重置</button>
            </div>

        </div>
    </div>

    <div class="row clearfix">
        <div class="col-md-12 column">
            <hr>
        </div>
    </div>
    <div class="row clearfix" style="max-height: 70%;overflow-y: auto;overflow-x: hidden">
        <div class="row clearfix">
            <div class="col-md-12 column">
                <div class="col-md-12 column" style="overflow: hidden">
                    <table id="dg" class="easyui-datagrid"
                           data-options="
								  	pageSize:'10',
								  	pageList:[10,20,30,40],
									pagination:true,
									rownumbers:true,
									url:'/orders/findMaterialPage',
									method:'get',
									width:'100%'">
                        <thead>
                        <tr>
                            <th data-options="field:'ck',checkbox: true"></th>
                            <th data-options="field:'ID'" hidden>Item ID(15%)</th>
                            <th data-options="field:'MATERIAL_CODE',width:'19%'">物资名称</th>
                            <th data-options="field:'MATERIAL_NAME',width:'19%'">物资编码</th>
                            <th data-options="field:'AMOUNT',width:'19%'">物资数量</th>
                            <th data-options="field:'ORDER_SOURCE',width:'19%',formatter: function(value,row,index){
                                                                                    if (value==null||value==''){
                                                                                        return '制造中心采购'
                                                                                    } else if(value=='C000-1'){
                                                                                        return '制造中心采购-公开求购';
                                                                                    }else{
                                                                                        return '制造中心采购-定向询价';
                                                                                    }
                                                                                } ">来源</th>
                            <th data-options="field:'status',width:'19%',formatter: function(value,row,index){
                                                                                    if (value=='C001-10'){
                                                                                        return '未确认'
                                                                                    } else {
                                                                                        return '确认';
                                                                                    }
                                                                                } ">状态</th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </div>


    <div class="row clearfix">
        <div class="col-md-12 column">
            <hr>
        </div>
    </div>

    <div class="col-md-12 column">
        <div class="col-md-12 column" style="padding-top:10px;text-align:center">
            <button type="button" onclick="btn4()"  class="btn btn-primary" >确定</button>
            <button type="button" onclick="btn5()"  class="btn btn-primary" >详情</button>
            <button type="button" onclick="btn6()"  class="btn btn-primary" >修改</button>
            <button type="button" onclick="btn7()"  class="btn btn-primary" >删除</button>
        </div>
    </div>
</div>

<!--<button type="button" class="btn btn-primary" id="empAdd" data-toggle="modal" data-target="#myModal">-->
<!--    添加-->
<!--</button>-->
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" arialabelledby="myModalLabel">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" arialabel="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel"></h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="ff" method="post">
                    <table class="table table-striped table-condensed">
                        <tr>
                            <td class="col-md-6">
                                <div class="col-md-4 column">
                                    <label for="xqjhbh" class="control-label">需求计划编号</label>
                                </div>
                                <div class="col-md-8 column">
                                    <input name="id" type="text" hidden>
                                    <input title="需求计划编号" readonly name="orderNum" type="text" class="form-control" id="xqjhbh">
                                </div>
                            </td>
                            <td class="col-md-6">
                                <div class="col-md-4 column">
                                    <label for="cpbm" class="control-label">产品编码	</label>
                                </div>
                                <div class="col-md-8 column">
                                    <input title="产品编码" readonly name="materialCode" type="text" class="form-control" id="cpbm">
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td class="col-md-6">
                                <div class="col-md-4 column">
                                    <label for="cpmc" class="control-label">产品名称</label>
                                </div>
                                <div class="col-md-8 column">
                                    <input title="产品名称" type="text" class="form-control" name="materialName" id="cpmc">
                                </div>
                            </td>
                            <td class="col-md-6">
                                <div class="col-md-4 column">
                                    <label for="sl" class="control-label">数量</label>
                                </div>
                                <div class="col-md-8 column">
                                    <input title="数量" type="text" class="form-control" name="amount" id="sl">
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td class="col-md-6">
                                <div class="col-md-4 column">
                                    <label for="jldw" class="control-label">计量单位</label>
                                </div>
                                <div class="col-md-8 column">
                                    <input title="计量单位" readonly type="text" name="measureUnit" class="form-control" id="jldw">
                                </div>
                            </td>
                            <td class="col-md-6">
                                <div class="col-md-4 column">
                                    <label for="ydj" class="control-label">预单价(元)</label>
                                </div>
                                <div class="col-md-8 column">
                                    <input title="预单价(元)" type="text" class="form-control" name="unitPrice" id="ydj">
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td class="col-md-6">
                                <div class="col-md-4 column">
                                    <label for="ksjhq" class="control-label">开始交货期</label>
                                </div>
                                <div class="col-md-8 column">
                                    <input title="开始交货期" type="datetime-local" class="form-control datepicker" name="jhq" id="ksjhq">
                                </div>
                            </td>
                            <td class="col-md-6">
                                <div class="col-md-4 column">
                                    <label for="ywy" class="control-label">业务员</label>
                                </div>
                                <div class="col-md-8 column">
                                    <input title="业务员" type="text" class="form-control " name="author" id="ywy">
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td class="col-md-6">
                                <div class="col-md-4 column">
                                    <label for="dzyj" class="control-label">电子邮件</label>
                                </div>
                                <div class="col-md-8 column">
                                    <input title="电子邮件" type="text" class="form-control " name="email" id="dzyj">
                                </div>
                            </td>
                            <td class="col-md-6">
                                <div class="col-md-4 column">
                                    <label for="lxdh" class="control-label">联系电话</label>
                                </div>
                                <div class="col-md-8 column">
                                    <input title="联系电话" type="text" class="form-control " name="phone" id="lxdh">
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td class="col-md-6" colspan="2">
                                <div class="col-md-4 column">
                                    <label for="lxcz" class="control-label">联系传真</label>
                                </div>
                                <div class="col-md-8 column">
                                    <input title="联系传真" type="text" class="form-control " name="fax" id="lxcz">
                                </div>
                            </td>

                        </tr>
                        <tr>
                            <td class="col-md-6" colspan="2">
                                <div class="col-md-2 column">
                                    <label for="bz" class="control-label">备注</label>
                                </div>
                                <div class="col-md-10 column">
                                    <textarea class="form-control" id="bz" name="remark" style="resize:none" rows="5"></textarea>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td class="col-md-6" colspan="2" style="text-align: right">
                                <button type="button" onclick="btn1()"  class="btn btn-primary">关闭</button>
                                <button type="button" onclick="btn10()" id="bntaa"  class="btn btn-primary">提交</button>
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
    </div>
</div>


<script>

    //判断是否能离开模糊窗口
    var pd=true

    //返回
    var btn1=function (){
        //如果能离开窗口 则直接隐藏模糊窗口
        if (pd){
            $('#myModal').modal("hide");
        }else{
            //如果不能离开窗口 则 再次确认
            if (confirm("你确定要关闭嘛")){
                $('#myModal').modal("hide");
            }
        }

    }

    //ajax修改
    var btn10=function (){
        $('#ff').form('submit', {
            url: '/orders/insetOrders',
            success: function(){
                //修改成功 则 重载表格数据，修改提示样式，改变是否能离开的判断值
                $('#dg').datagrid('reload');
                $('#myModalLabel').html("修改");
                pd=true;
            }
        });
    }

    //模糊查询
    var btn2=function (){
        var a1=$("#a1").val();
        var a2=$("#a2").val();
        var a3=$("#a3").val();
        $('#dg').datagrid({
            url:'/orders/findMaterialPage',
            method:'get',
            queryParams: {
                materialCode:a1,
                materialName:a2,
                zt:a3
            }
        });
    }

    //重置搜索数据
    var btn3=function(){
        $("#a1").val("");
        $("#a2").val("");
        $("#a3").val("全部");
    }

    //批量确定
    var btn4=function (){
        var rows=$("#dg").datagrid("getSelections");
        if (rows.length!=0){
            for (var i = 0; i <rows.length ; i++) {
                if (rows[i].status=='C001-10'){
                    $.ajax({
                        url: "/idMapping/updatebyStatus?OrdersId=" + rows[i].ID,
                        method: "get",
                        success: function (data) {
                            $('#dg').datagrid('reload');
                        }
                    })
                }
            }
        }
    }

    //打开模糊窗口 查看详情
    var btn5=function (){
        var row=$("#dg").datagrid("getSelected");
        if (row!=null){
            $.ajax({
                url: "/orders/findbyid?id="+row.ID,
                method: "get",
                success: function(data){
                    pd=true;
                    $("button[id=bntaa]").hide();
                    $("input[name=id]").val(data.id);
                    $("input[name=orderNum]").val(data.orderNum).attr("readonly","readonly");
                    $("input[name=materialCode]").val(data.materialCode).attr("readonly","readonly");
                    $("input[name=materialName]").val(data.materialName).attr("readonly","readonly");
                    $("input[name=amount]").val(data.amount).attr("readonly","readonly");
                    $("input[name=measureUnit]").val(data.measureUnit).attr("readonly","readonly");
                    $("input[name=unitPrice]").val(data.unitPrice).attr("readonly","readonly");
                    $("input[name=jhq]").val(data.startDate).attr("readonly","readonly");
                    $("input[name=author]").val(data.author).attr("readonly","readonly");
                    $("input[name=email]").val(data.email).attr("readonly","readonly");
                    $("input[name=phone]").val(data.phone).attr("readonly","readonly");
                    $("input[name=fax]").val(data.fax).attr("readonly","readonly");
                    $("textarea[name=remark]").text(data.remark).attr("readonly","readonly");
                    $('#myModal').modal("show");
                    $('#myModalLabel').text("详情")
                }
            });
        }


    }

    //打开模糊窗口 修改
    var btn6=function (){
        var row=$("#dg").datagrid("getSelected");
        if (row!=null){
            if (row.status=='C001-10'){
                $.ajax({
                    url: "/orders/findbyid?id="+row.ID,
                    method: "get",
                    success: function(data){
                        pd=false;
                        $("button[id=bntaa]").show();
                        $("input[name=id]").val(data.id);
                        $("input[name=orderNum]").val(data.orderNum).attr("readonly","readonly");
                        $("input[name=materialCode]").val(data.materialCode).attr("readonly","readonly");
                        $("input[name=materialName]").val(data.materialName).attr("readonly","readonly");
                        $("input[name=amount]").val(data.amount).removeAttr("readonly");
                        $("input[name=measureUnit]").val(data.measureUnit).attr("readonly","readonly");
                        $("input[name=unitPrice]").val(data.unitPrice).removeAttr("readonly");
                        $("input[name=jhq]").val(data.startDate).removeAttr("readonly");
                        $("input[name=author]").val(data.author).removeAttr("readonly");
                        $("input[name=email]").val(data.email).removeAttr("readonly");
                        $("input[name=phone]").val(data.phone).removeAttr("readonly");
                        $("input[name=fax]").val(data.fax).removeAttr("readonly");
                        $("textarea[name=remark]").text(data.remark).removeAttr("readonly");
                        $('#myModal').modal("show");
                        $('#myModalLabel').html("修改")
                    }
                });
            }
        }
    }

    //input内容发生改变时提示
    $("input[title]").each(function (){
        $(this).on("change",function (){
            $('#myModalLabel').html("修改<span style='color: red'>*</span>");
        })
    })

    //批量删除
    var btn7=function (){
        var rows=$("#dg").datagrid("getSelections");
        if (rows.length!=0){
            for (var i = 0; i <rows.length ; i++) {
                if (rows[i].status=='C001-10'){
                    $.ajax({
                        url: "/orders/deletebyID?OrdersId=" + rows[i].ID,
                        method: "get",
                        success: function (data) {

                        }
                    })
                }
            }
            $('#dg').datagrid('reload');
        }
    }

</script>


</body>

</html>